#!/bin/sh

VERSION=20080526
GUTENMARK_SRC_DIR=~/dev/GutenMark-source
LANGD=/usr/share/GutenMark
pushd $GUTENMARK_SRC_DIR
make clean
make CC=arm-apple-darwin-gcc STRIP=arm-apple-darwin-strip
popd

mkdir -p dist/usr/bin
mkdir -p dist/usr/share/GutenMark
mkdir -p dist/etc/
cp $GUTENMARK_SRC_DIR/GutenMark dist/usr/bin/
cp $GUTENMARK_SRC_DIR/GutenUtilities/GutenSplit dist/usr/bin/

WORDLISTFILES="english.names.gz english.words.gz french.names.gz french.words.gz german.words.gz italian.words.gz latin.words.gz nonenglish.words.gz spanish.words.gz special.words.gz US.places.gz"

pushd dist/usr/share/GutenMark
for i in $WORDLISTFILES ; do
    if [ ! -f $i ] ; then
        wget http://www.sandroid.org/GutenMark/wasftp.GutenMark/Wordlists/$i
    fi
done
popd

cat >dist/etc/GutenMark.cfg <<EOF
[english]
native=$LANGD/special.words.gz English
native=$LANGD/english.names.gz English
native=$LANGD/US.places.gz English
native=$LANGD/french.names.gz French
native=$LANGD/english.words.gz English
foreign=$LANGD/german.words.gz German
foreign=$LANGD/french.words.gz French
foreign=$LANGD/latin.words.gz Latin
foreign=$LANGD/italian.words.gz Italian
foreign=$LANGD/spanish.words.gz Spanish

[en]
native=$LANGD/special.words.gz English
native=$LANGD/english.names.gz English
native=$LANGD/US.places.gz English
native=$LANGD/french.names.gz French
native=$LANGD/english.words.gz English
foreign=$LANGD/german.words.gz German
foreign=$LANGD/french.words.gz French
foreign=$LANGD/latin.words.gz Latin
foreign=$LANGD/italian.words.gz Italian
foreign=$LANGD/spanish.words.gz Spanish

[fr]
native=$LANGD/french.names.gz French
native=$LANGD/english.names.gz English
native=$LANGD/US.places.gz English
native=$LANGD/french.words.gz French
foreign=$LANGD/special.words.gz English
foreign=$LANGD/english.words.gz English
foreign=$LANGD/german.words.gz German
foreign=$LANGD/latin.words.gz Latin
foreign=$LANGD/italian.words.gz Italian
foreign=$LANGD/spanish.words.gz Spanish

[es]
native=$LANGD/french.names.gz French
native=$LANGD/english.names.gz English
native=$LANGD/US.places.gz English
native=$LANGD/spanish.words.gz Spanish
foreign=$LANGD/french.words.gz French
foreign=$LANGD/special.words.gz English
foreign=$LANGD/english.words.gz English
foreign=$LANGD/german.words.gz German
foreign=$LANGD/latin.words.gz Latin
foreign=$LANGD/italian.words.gz Italian

[it]
native=$LANGD/french.names.gz French
native=$LANGD/english.names.gz English
native=$LANGD/US.places.gz English
native=$LANGD/italian.words.gz Italian
foreign=$LANGD/latin.words.gz Latin
foreign=$LANGD/spanish.words.gz Spanish
foreign=$LANGD/french.words.gz French
foreign=$LANGD/special.words.gz English
foreign=$LANGD/english.words.gz English
foreign=$LANGD/german.words.gz German

[de]
native=$LANGD/french.names.gz French
native=$LANGD/english.names.gz English
native=$LANGD/US.places.gz English
native=$LANGD/german.words.gz German
foreign=$LANGD/italian.words.gz Italian
foreign=$LANGD/latin.words.gz Latin
foreign=$LANGD/spanish.words.gz Spanish
foreign=$LANGD/french.words.gz French
foreign=$LANGD/special.words.gz English
foreign=$LANGD/english.words.gz English
EOF

pushd dist
ZIP_NAME=gutenmark-iphone.$VERSION.zip
zip -r $ZIP_NAME etc usr
mv gutenmark-iphone.$VERSION.zip ../
popd

MD5=`md5sum $ZIP_NAME | cut -d" " -f 1`
SIZE=`ls -l $ZIP_NAME | cut -d" " -f 5`

sed -e "s/VALUE_FILENAME/$ZIP_NAME/g" -e "s/VALUE_SIZE/$SIZE/g" -e "s/VALUE_HASH/$MD5/g" -e "s/VALUE_VERSION/$VERSION/g" < gutenmark.plist > ../gutenberg_scifi/plists/gutenmark.plist

